<?php

  require_once('./includes/db.php');
  $msg = '';



  unset($_POST['cpassword']);

  $_POST['password'] = md5($_POST['password']);

  $_POST['lang'] = implode(',',$_POST['lang']);
  $_POST['hobbies'] = implode(',',$_POST['hobbies']);
  $_POST['added_date'] = date('Y-m-d H:i:s');
  $_POST['status'] = '1';

  $_POST = arrayCleanup($_POST);

  #####################################
  # Sucurity Code Check               #
  #####################################

//pr1($_POST);
//pr1($_SESSION);
if($_POST['captcha'] != $_SESSION['secretword']){
  setFlashMessage("Security Code incorrect");
  jsRedirect('register.php');
} else {
  unset($_POST['captcha']);
}


  #####################################
  pr($_POST);
  pr($_FILES);
  ######################################
  $uploadResult = upload('avatar','./uploads',array('jpg','jpeg','png'),1.0);
  pr1($uploadResult);
  $_POST['avatar'] = $uploadResult['fileName'];


if ($uploadResult['flag'] == true )
{
    ini_set('memory_limit', '-1');

    $imageName = $uploadResult['fileName'];
    $thumbSrc = "./uploads/$imageName";
    /*** Start Create Dir if not exists***/
   if(!is_dir('./uploads/chat')){
     mkdir("./uploads/chat");
   }
   if(!is_dir('./uploads/wall')){
     mkdir("./uploads/wall");
   }
    /*** End Create Dir if not exists***/
    // include image processing code
    require_once('./thumb/image.class.php');
    $img = new Zubrag_image;
    $img->max_x        = 100;
    $img->max_y        = 70;
    $img->GenerateThumbFile
    ($thumbSrc, "./uploads/wall/$imageName");//700/50

    $img = new Zubrag_image;
    $img->max_x        = 50;
    $img->max_y        = 20;
    $img->GenerateThumbFile
    ($thumbSrc, "./uploads/chat/$imageName");
  #####################################


  $id = insert('users',$_POST);
    setFlashMessage("Record Inserted on id $id");
   jsRedirect('show_all_users.php');

} else {

  jsRedirect('register.php');
}

